<?php
/**
 * Created by PhpStorm.
 * User: kamlyli
 * Date: 2017/8/12
 * Time: 11:30
 */

namespace app\api\controller\v1;


use app\api\model\ExaminationRecord;
use app\api\model\User;

class Ranking extends Base
{
    public function index()
    {
        $exam_record = new ExaminationRecord();
        $exam_record = $exam_record->where('score', '>', '0')->order('score desc')->group("userId")->limit(10)->select()->toArray();

        for ($i = 0; $i < count($exam_record); $i++) {
            $user = new User();
            $user = $user->where(['id' => $exam_record[$i]['userId']])->find()->toArray();
            $exam_record[$i]['user_info'] = $user;
        }

        return json_info($exam_record);
    }
}